﻿using RotovapPlatform.Domain.Business.Recipes.Entities;
using RotovapPlatform.Domain.Common;
using RotovapPlatform.Domain.Services.Scheduling;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using RotovapPlatform.Domain.Business.Machine.Enums;
using static RotovapPlatform.Domain.Business.Machine.Enums.ExperimentConfigEnums;

namespace RotovapPlatform.Application.Services.Scheduling
{
	/// <summary>
	/// 任务调度应用服务接口
	/// </summary>
	public interface ITaskSchedulingAppService
	{
		/// <summary>
		/// 当前实验组变更事件
		/// </summary>
		event Action<Guid?> CurrentExperimentGroupChanged;

		/// <summary>
		/// 获取当前活动的实验组ID
		/// </summary>
		/// <returns>当前实验组ID，如果没有活动的实验组则返回null</returns>
		Task<Guid?> GetCurrentExperimentGroupIdAsync();

		/// <summary>
		/// 设置当前活动的实验组
		/// </summary>
		/// <param name="experimentGroupId">实验组ID</param>
		/// <returns>操作结果</returns>
		Task<OperationResult> SetCurrentExperimentGroupAsync(Guid? experimentGroupId);

		/// <summary>
		/// 启动实验组中的下一个实验
		/// </summary>
		/// <param name="experimentGroup">实验组</param>
		/// <returns>启动的实验实例</returns>
		Task<Experiment> StartNextExperimentAsync(ExperimentGroup experimentGroup);

		/// <summary>
		/// 获取实验组中所有实验的列表
		/// </summary>
		/// <param name="experimentGroupId">实验组ID</param>
		/// <returns>实验列表</returns>
		Task<List<Experiment>> GetExperimentsInGroupAsync(Guid experimentGroupId);

		/// <summary>
		/// 获取指定实验的最新状态
		/// </summary>
		/// <param name="experimentId">实验ID</param>
		/// <returns>最新的实验状态</returns>
		Task<Experiment> GetExperimentStatusAsync(Guid experimentId);

		/// <summary>
		/// 验证实验组配方
		/// </summary>
		/// <param name="experimentGroupId">实验组ID</param>
		/// <returns>验证结果</returns>
		Task<ValidationResultDto> ValidateExperimentGroupAppAsync(string experimentGroupId);

		/// <summary>
		/// 分解实验组为单个实验任务（并保存到数据库）
		/// </summary>
		/// <param name="experimentGroupId">实验组ID</param>
		/// <returns>分解结果</returns>
		Task<List<Experiment>> DecomposeExperimentGroupAppAsync(Guid experimentGroupId);

		/// <summary>
		/// 分解实验组为单个实验任务（不保存到数据库，仅用于UI显示）
		/// </summary>
		/// <param name="experimentGroupId">实验组ID</param>
		/// <returns>分解后的实验列表</returns>
		Task<List<Experiment>> DecomposeExperimentGroupForUIAsync(Guid experimentGroupId);

		/// <summary>
		/// 启动实验组
		/// </summary>
		/// <param name="experimentGroup">实验组</param>
		/// <returns>操作结果</returns>
		Task<OperationResult> StartExperimentGroupAsync(ExperimentGroup experimentGroup);
	}
}